package com.ucode.model.hrm.form;

import cn.hutool.core.util.ObjUtil;
import com.ucode.model.hrm.HrmEmployeePicInfo;
import com.ucode.model.hrm.HrmFamilyMember;
import com.ucode.model.hrm.HrmStudyExperience;
import com.ucode.model.hrm.HrmWorkExperience;
import com.ucode.model.hrm.enums.HrmEmploymentTypeEnum;
import com.ucode.tool.base.enums.EducationLevelEnum;
import com.ucode.tool.base.enums.MaritalStatusEnum;
import com.ucode.tool.base.enums.PoliticalStatusTypeEnum;
import com.ucode.tool.validator.IDCard;
import com.ucode.tool.validator.InEnum;
import com.ucode.tool.validator.Mobile;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;

import javax.validation.Valid;
import javax.validation.constraints.AssertTrue;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.List;

@Schema(description = "人力资源管理系统 - 员工Form")
@Data
@EqualsAndHashCode
@ToString(callSuper = true)
public class HrmEmployeeForm{
    /**
     * 头像
     */
    @Schema(description = "头像", requiredMode = Schema.RequiredMode.AUTO)
    @Size(max = 256, message = "头像不能超过 256 个字符")
    private String avatar;
    /**
     * 真实姓名
     */
    @Schema(description = "真实姓名", requiredMode = Schema.RequiredMode.REQUIRED)
    @NotBlank(message = "真实姓名不能为空")
    @Size(max = 50, message = "真实姓名不能超过 50 个字符")
    private String realName;
    /**
     * 性别：0-未填，1-男，2-女
     */
    @Schema(description = "性别", requiredMode = Schema.RequiredMode.REQUIRED)
    @NotNull(message = "性别不能为空")
    @InEnum(value= com.ucode.tool.base.enums.SexEnum.class)
    private Integer gender;
    /**
     * 民族
     */
    @Schema(description = "民族", requiredMode = Schema.RequiredMode.REQUIRED)
    @NotBlank(message = "民族不能为空")
    @Size(max = 20, message = "民族不能超过 20 个字符")
    private String ethnicity;
    /**
     * 出生日期
     */
    @Schema(description = "民族", requiredMode = Schema.RequiredMode.AUTO)
    private LocalDate birthDate;
    /**
     * 学历
     * @see HrmEmploymentTypeEnum
     */
    @Schema(description = "学历", requiredMode = Schema.RequiredMode.REQUIRED)
    @NotNull(message = "学历不能为空")
    @InEnum(value= EducationLevelEnum.class)
    private Integer education;
    /**
     * 婚姻状况
     * @see com.ucode.tool.base.enums.MaritalStatusEnum
     */
    @Schema(description = "婚姻状况", requiredMode = Schema.RequiredMode.REQUIRED)
    @NotNull(message = "婚姻状况不能为空")
    @InEnum(value= MaritalStatusEnum.class)
    private Integer maritalStatus;
    /**
     * 政治面貌
     * @see com.ucode.tool.base.enums.PoliticalStatusTypeEnum
     */
    @Schema(description = "政治面貌", requiredMode = Schema.RequiredMode.REQUIRED)
    @NotNull(message = "政治面貌不能为空")
    @InEnum(value= PoliticalStatusTypeEnum.class)
    private Integer politicalStatus;
    /**
     * 入党时间
     */
    @Schema(description = "入党时间", requiredMode = Schema.RequiredMode.AUTO)
    private LocalDate entryTime;
    /**
     * 英语水平
     */
    @Schema(description = "英语水平", requiredMode = Schema.RequiredMode.AUTO)
    @Size(max = 20, message = "英语水平不能超过 20 个字符")
    private String englishProficiency;
    /**
     * 其他语言
     */
    @Schema(description = "其他语言", requiredMode = Schema.RequiredMode.AUTO)
    @Size(max = 20, message = "其他语言不能超过 20 个字符")
    private String otherLanguages;
    /**
     * 驾驶证类型
     * DriverLicenseTypeEnum
     */
    @Schema(description = "其他语言", requiredMode = Schema.RequiredMode.AUTO)
    @Size(max = 10, message = "其他语言不能超过 10 个字符")
    private String driversLicenseType;
    /**
     * 身高(cm)
     */
    @Schema(description = "身高(cm)", requiredMode = Schema.RequiredMode.AUTO)
    private Integer height;

    /**
     * 体重(kg)
     */
    @Schema(description = "体重(kg)", requiredMode = Schema.RequiredMode.AUTO)
    private BigDecimal weight;
    //户籍信息
    /**
     * 户口类型(农业/非农业)
     */
    @Schema(description = "户口类型", requiredMode = Schema.RequiredMode.AUTO)
    @NotBlank(message = "户口类型不能为空")
    @Size(max = 20, message = "户口类型不能超过 20 个字符")
    private String householdType;
    ///**
    // * 户籍所在地(户籍)
    // */
    //@Schema(description = "户籍所在地", requiredMode = Schema.RequiredMode.AUTO)
    //@NotBlank(message = "户籍所在地不能为空")
    //@Size(max = 50, message = "户籍所在地不能超过 50 个字符")
    //private String registeredResidence;
    /**
     * 户籍所在地详细地址
     */
    @Schema(description = "户籍所在地详细地址", requiredMode = Schema.RequiredMode.AUTO)
    @NotBlank(message = "户籍所在地详细地址不能为空")
    @Size(max = 255, message = "户籍所在地详细地址不能超过 255 个字符")
    private String detailedAddress;
    /**
     * 现在居住地址(现居住)
     */
    @Schema(description = "户籍所在地详细地址", requiredMode = Schema.RequiredMode.AUTO)
    @NotBlank(message = "户籍所在地详细地址不能为空")
    @Size(max = 255, message = "户籍所在地详细地址不能超过 255 个字符")
    private String residentialAddress;
    //紧急联系人
    /**
     * 紧急联系人姓名
     */
    @Schema(description = "紧急联系人姓名", requiredMode = Schema.RequiredMode.AUTO)
    @Size(max = 50, message = "紧急联系人姓名不能超过 50 个字符")
    private String cnontactName;
    /**
     * 紧急联系人与本人关系（父母/配偶/子女/朋友等）
     */
    @Schema(description = "紧急联系人与本人关系", requiredMode = Schema.RequiredMode.AUTO)
    @Size(max = 20, message = "紧急联系人与本人关系不能超过 20 个字符")
    private String relationship;
    /**
     * 紧急联系人联系电话
     */
    @Schema(description = "紧急联系人联系电话", requiredMode = Schema.RequiredMode.AUTO)
    @Size(max = 20, message = "紧急联系人联系电话不能超过 20 个字符")
    private String cnontactPhone;
    /**
     * 紧急联系人姓名
     */
    @Schema(description = "紧急联系人姓名", requiredMode = Schema.RequiredMode.AUTO)
    @Size(max = 50, message = "紧急联系人姓名不能超过 50 个字符")
    private String cnontactName1;
    /**
     * 紧急联系人与本人关系（父母/配偶/子女/朋友等）
     */
    @Schema(description = "紧急联系人与本人关系", requiredMode = Schema.RequiredMode.AUTO)
    @Size(max = 20, message = "紧急联系人与本人关系不能超过 20 个字符")
    private String relationship1;
    /**
     * 紧急联系人联系电话
     */
    @Schema(description = "紧急联系人联系电话", requiredMode = Schema.RequiredMode.AUTO)
    @Size(max = 20, message = "紧急联系人联系电话不能超过 20 个字符")
    private String cnontactPhone1;

    //教育经历
    @Schema(description = "教育经历", requiredMode = Schema.RequiredMode.AUTO)
    private List<@Valid HrmStudyExperience> studyExperiences;
    //家庭成员
    @Schema(description = "家庭成员", requiredMode = Schema.RequiredMode.AUTO)
    private List<@Valid HrmFamilyMember> familyMembers;
    //工作经历
    @Schema(description = "工作经历", requiredMode = Schema.RequiredMode.AUTO)
    private List<@Valid HrmWorkExperience> workExperiences;
    // 员工图片资料
    @Schema(description = "工作经历", requiredMode = Schema.RequiredMode.AUTO)
    @Valid
    private HrmEmployeePicInfo pictureInfo;
    /**
     * 身份证号
     */
    @Schema(description = "身份证号", requiredMode = Schema.RequiredMode.REQUIRED)
    @NotBlank(message = "身份证号不能为空")
    @IDCard
    @Size(max = 50, message = "身份证号不能超过 50 个字符")
    private String idCardNumber;
    /**
     * 电话
     */
    @Schema(description = "电话", requiredMode = Schema.RequiredMode.REQUIRED)
    @NotBlank(message = "电话不能为空")
    @Mobile
    @Size(max = 20, message = "电话不能超过 20 个字符")
    private String phone;

    /**
     *  联系邮箱
     */
    @Schema(description = "联系邮箱", requiredMode = Schema.RequiredMode.AUTO)
    @Size(max = 50, message = "联系邮箱不能超过 50 个字符")
    private String email;

    /**
     * 入职日期
     */
    @Schema(description = "入职日期", requiredMode = Schema.RequiredMode.REQUIRED)
    @NotNull(message = "入职日期不能为空")
    private LocalDate hireDate;

    /**
     * 试用结束日期
     */
    @Schema(description = "试用结束日期", requiredMode = Schema.RequiredMode.AUTO)
    private LocalDate trialEndDate;
    /**
     * 合同到期日期
     */
    @Schema(description = "合同到期日期", requiredMode = Schema.RequiredMode.REQUIRED)
    @NotNull(message = "合同到期日期不能为空")
    private LocalDate contractEndDate;

    /**
     * 转正日期
     */
    @Schema(description = "转正日期", requiredMode = Schema.RequiredMode.AUTO)
    private LocalDate regularizationDate;
    /**
     * 编制类型：1-实习，2-试用，3-正式，4-离职
     * @see HrmEmploymentTypeEnum
     */
    @Schema(description = "编制类型", requiredMode = Schema.RequiredMode.REQUIRED)
    @NotNull(message = "编制类型不能为空")
    @InEnum(value= HrmEmploymentTypeEnum.class)
    private Integer employmentType;

    /**
     * 离职日期
     */
    @Schema(description = "离职日期", requiredMode = Schema.RequiredMode.AUTO)
    private LocalDate resignationDate;
    /**
     * 入职客户公司项目ID
     */
    @Schema(description = "入职客户公司项目ID", requiredMode = Schema.RequiredMode.AUTO)
    private Long projectId;
    /**
     * 自定义用工单位
     */
    @Schema(description = "自定义用工单位", requiredMode = Schema.RequiredMode.AUTO)
    @Size(max = 500, message = "自定义用工单位不能超过 500 个字符")
    private String customCompany;
    /**
     * 入职外部部门名称
     */
    @Schema(description = "入职外部部门名称", requiredMode = Schema.RequiredMode.REQUIRED)
    @NotBlank(message = "入职外部部门名称不能为空")
    @Size(max = 50, message = "入职外部部门名称不能超过 50 个字符")
    private String departmentName;
    /**
     * 入职外部职位名称
     */
    @Schema(description = "入职外部职位名称", requiredMode = Schema.RequiredMode.REQUIRED)
    @NotBlank(message = "入职外部职位名称不能为空")
    @Size(max = 50, message = "入职外部职位名称不能超过 50 个字符")
    private String positionName;

    /**
     * 工作地点
     */
    @Schema(description = "工作地点", requiredMode = Schema.RequiredMode.REQUIRED)
    @NotBlank(message = "工作地点不能为空")
    @Size(max = 100, message = "工作地点不能超过 100 个字符")
    private String workLocation;

    @Schema(description = "考勤打卡", requiredMode = Schema.RequiredMode.AUTO)
    private Long attCfgId;

    @AssertTrue(message = "试用结束时间必须要大于入职时间")
    public boolean isTimeIntervalCheck() {
        if(ObjUtil.isNull(trialEndDate)){
            return true;
        }
        if(this.trialEndDate.isAfter(this.hireDate)){
            return true;
        }
        return false;
    }

}
